<template>
  <div class="main">
    <h2>分期管理</h2>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <!-- <el-table-column
          align="center"
          prop="id"
          label="Id"
          min-width="13%"
        /> -->

        <el-table-column
          label="序号"
          type="index"
          min-width="13%"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="orderId"
          label="订单号"
          min-width="13%"
        />

        <el-table-column
          align="center"
          prop="userName"
          label="用户姓名"
          min-width="6%"
        />

        <el-table-column
          align="center"
          prop="userPhone"
          label="手机号"
          min-width="10%"
        />

        <el-table-column
          align="center"
          prop="userIdCard"
          label="身份证"
          min-width="13%"
        />

        <el-table-column
          align="center"
          prop="createDate"
          label="申请日期"
          min-width="8%"
        />

        <el-table-column
          align="center"
          prop="totalPrice"
          label="总金额"
          min-width="8%"
        >
          <template slot-scope="Scope">
            <span>￥{{ Scope.row.totalPrice/100 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="period"
          label="分期数"
          min-width="5%"
        />

        <el-table-column
          align="center"
          prop="state"
          label="状态"
          min-width="7%"
        >
          <template slot-scope="Scope">
            <span v-if="Scope.row.state==-1" style="color:red">已驳回</span>
            <span v-if="Scope.row.state==0" style="color:gray">未处理</span>
            <span v-if="Scope.row.state==1" style="color:green">已通过</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作" min-width="17%">
          <template slot-scope="Scope">
            <el-button v-if="Scope.row.state==0" type="primary" icon="el-icon-edit" @click="adultStage(Scope.row.orderId,1)">通过</el-button>
            <el-button v-if="Scope.row.state==0" type="danger" icon="el-icon-delete" @click="adultStage(Scope.row.orderId,-1)">驳回</el-button>
            <span v-if="Scope.row.state!=0" style="color:green">已完成处理</span>
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5,10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getAll, updateStage } from '@/api/stage'
export default {
  components: {},

  data() {
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      list: [],
      listLoading: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 每页下拉显示数据
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    fetchData() {
      getAll().then((resp) => {
        this.list = resp.obj
        for (var i = 0; i < this.list.length; i++) {
          this.list[i].orderId = this.list[i].orderId.split(';')[0]
        }
      })
    },
    adultStage(id, state) {
      updateStage(id, state).then((resp) => {
        console.log(id)
        this.$notify({
          title: '审核成功',
          type: 'success'
        })
        this.fetchData()
      })
    }

  }
}
</script>

<style>
    #main{
        margin-left: 5px;
        margin-right: 5px;
    }

    #table-area{

        margin-left: 10px;
        margin-right: 10px;
    }
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
      }
    .avatar-uploader .el-upload:hover {
      border-color: #409EFF;
    }
    .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      line-height: 178px;
      text-align: center;
    }
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }

    h2{
      margin:15px;
    }
</style>
